QCustomPlot实现图例置于底部 您所在的位置:网站首页 qcustomplot 图片 QCustomPlot实现图例置于底部

QCustomPlot实现图例置于底部

2024-06-22 01:25| 来源: 网络整理| 查看: 265

简介:QCustomPlot是一个小型的Qt画图表的类。只需要包含.h和.cpp文件即可。支持曲线和柱状图等,具体查看官方文档。 http://www.qcustomplot.com/。

此例是实现图例位置的置于底部(此例是基于2.0.0版本)。查看相关Layouts帮助说明。默认是按照一行一列的方式添加的item。只要更改item的布局方式即可 效果如下

实现代码如下

void CMoniter3Widget::setLegendPosition( QCustomPlot *plot ) { int count = plot->plotLayout()->rowCount(); QMargins marg(100,1,10,1); if (plot->graphCount() == 6) { marg.setLeft(50); plot->legend->addElement(0,1,plot->legend->item(1)); plot->legend->addElement(0,2,plot->legend->item(2)); plot->legend->addElement(1,0,plot->legend->item(3)); plot->legend->addElement(1,1,plot->legend->item(4)); plot->legend->addElement(1,2,plot->legend->item(5)); } else if (plot->graphCount() == 4) { plot->legend->addElement(0,1,plot->legend->item(1)); plot->legend->addElement(1,0,plot->legend->item(2)); plot->legend->addElement(1,1,plot->legend->item(3)); } else { //plot->legend->addElement(0,1,plot->legend->item(0)); plot->legend->addElement(0,1,plot->legend->item(1)); marg.setLeft(200); } plot->legend->setMargins(marg); plot->legend->setBorderPen(Qt::NoPen); plot->plotLayout()->addElement(count,0,plot->legend); plot->plotLayout()->setRowStretchFactor(count, 0.001); }

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有